import { fromJS } from 'immutable';
import { constant } from "./index";

const defaultStore = fromJS({
  topList: [],
  recommondList:[],
  list:[],
  writeList:[],
  pageIndex:1,
  showScrollTop:false,
});

const reduceHandler = (store = defaultStore, action) => {
  switch(action.type){
    case constant.TOP_LIST:
      return store.set("topList",action.value);
    case constant.SET_HOME_DATA:
      //set可以多次链式使用,可以用merge方法实现更加方便
      // return store.set(key1,value1).set(key2,value2)
      return store.merge({
        topList:fromJS(action.value.topList),
        recommondList:fromJS(action.value.recommondList),
        list:fromJS(action.value.list),
        writeList:fromJS(action.value.writeList)
      })
    case constant.LOAD_MORE:
      return store.merge({
        recommondList:store.get("recommondList").concat(action.list),
        pageIndex:action.nextPage
      })
    case constant.SHOW_SCROLL_TOP:
      return store.set("showScrollTop",fromJS(action.value));
    default:
      return store;
  }
}

export default reduceHandler;



